package com.yuanqi.dz.dc.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import pnbclient.helper.StringHelper;

public class DZConfigRead{
	private static Properties p = null;
	private static Object lock = new Object();
	public static String getProperties(String key){
		if(p != null){
			return p.getProperty(key);
		}
		InputStream input = null;
		String message = null;
		try {
			synchronized (lock) {
				if(p != null){
					return p.getProperty(key);
				}
				input = DZConfigRead.class.getClassLoader().getResourceAsStream("dz_config.ini");
				Properties tmp = new Properties();
				tmp.load(input);
				p = tmp;
				message = p.getProperty(key);
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if(input != null)
				try {
					input.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
		}
		return message;
	}


	public  static  int[] getProperties2(String key){
		String  p=getProperties(key);
		if(!StringHelper.isEmpty(p)){
			String[]  s=  p.split("-");
			if(s.length==2){
				try {
					int[]  s2=new int[]{Integer.valueOf(s[0]),Integer.valueOf(s[1])};
					return  s2;
				} catch (Exception e) {
					return  null;
				}
			}
			return null;
		}
		return null;
	}
	public static void main(String[] args) {
		String s= getProperties("HostAddress");
		System.out.println(s);
	}



}
